package com.berchen.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Combine {
//    private static List<String> erweiList=new ArrayList<>();
//	private static ArrayList<Integer> tmpArr = new ArrayList<>();
/*	public static void main(String[] args) {
		int [] com = {1,2,3,4,5};
		int k = 4;
		if(k > com.length || com.length <= 0){
			return ;
		}
//		combine(0 ,k ,com);

        int[][] te = getDiagIndex(com,k);
        for(int i =0;i<te.length;i++){
            System.out.println(Arrays.toString(te[i]));
        }

//        System.out.println(erweiList);
	}*/
    public static void main(String[] args) {
        List<String> [] diagNames=new List[5];
        diagNames[0]=Arrays.asList("A","G");
        diagNames[1]=Arrays.asList("C","F");
        diagNames[2]=Arrays.asList("L","O");
        diagNames[3]=Arrays.asList("E","B");
        diagNames[4]=Arrays.asList("Z","A");

        TestMerge testMerge = new TestMerge();
        List<String> diag = testMerge.getDiagNew(diagNames);
        System.out.println(diag);
    }
	public static int[][] getDiagIndex(int [] temp,int column){
        List<String> erweiList=new ArrayList<>();
        List<Integer> tmpArr = new ArrayList<>();
	    combine(0,column,temp,erweiList,tmpArr);
        int row = erweiList.size();
        int[][] arr=new int[row][column];
        for(int i =0;i<erweiList.size();i++){

            String str = erweiList.get(i);
            str=str.substring(1,str.length()-1);
            String[] split = str.split(",");
            for (int j =0;j<split.length;j++){
                arr[i][j]=Integer.parseInt(split[j].trim());
            }
        }
        return arr;
    }

    /**
     * 索引
     * @param index
     * @param k
     * @param arr
     */
	public static void combine(int index,int k,int []arr,List<String> erweiList,List<Integer> tmpArr) {
		if(k == 1){
			for (int i = index; i < arr.length; i++) {
				tmpArr.add(arr[i]);
				erweiList.add(tmpArr.toString());
//				System.out.println(tmpArr.toString());
				tmpArr.remove((Object)arr[i]);
			}
		}else if(k > 1){
			for (int i = index; i <= arr.length - k; i++) {
				tmpArr.add(arr[i]);
				combine(i + 1,k - 1, arr,erweiList,tmpArr);
				tmpArr.remove((Object)arr[i]);
			}
		}else{
			return ; 
		}
	}
}